﻿@inject Nop.Core.Domain.Common.AdminAreaSettings adminAreaSettings
@{
    Layout = "_ConfigurePlugin";

    var defaultGridPageSize = adminAreaSettings.DefaultGridPageSize;
    var gridPageSizes = adminAreaSettings.GridPageSizes;
}

<form asp-controller="PickupInStore" asp-action="Configure" method="post" id="pickup-instore-form">
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <div id="pickup-points-grid"></div>
                <script>
                    $(document).ready(function() {
                        $("#pickup-points-grid").kendoGrid({
                            dataSource: {
                                type: "json",
                                transport: {
                                    read: {
                                        url: "@Html.Raw(Url.Action("List", "PickupInStore"))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    },
                                    destroy: {
                                        url: "@Html.Raw(Url.Action("Delete", "PickupInStore"))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    }
                                },
                                schema: {
                                    data: "Data",
                                    total: "Total",
                                    errors: "Errors",
                                    model: {
                                        id: "Id"
                                    }
                                },
                                requestEnd: function (e) {
                                    if (e.type == "update") {
                                        this.read();
                                    }
                                },
                                error: function(e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                    pageSize: @(defaultGridPageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                            },
                            pageable: {
                                refresh: true,
                                pageSizes: [@(gridPageSizes)],
                                @await Html.PartialAsync("_GridPagerMessages")
                            },
                            editable: {
                                confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                mode: "inline"
                            },
                            scrollable: false,
                            columns: [ {
                                field: "Name",
                                width: 200,
                                title: "@T("Plugins.Pickup.PickupInStore.Fields.Name")"
                            }, {
                                field: "OpeningHours",
                                width: 200,
                                title: "@T("Plugins.Pickup.PickupInStore.Fields.OpeningHours")"
                            }, {
                                field: "PickupFee",
                                width: 100,
                                title: "@T("Plugins.Pickup.PickupInStore.Fields.PickupFee")"
                            }, {
                                field: "DisplayOrder",
                                width: 100,
                                title: "@T("Plugins.Pickup.PickupInStore.Fields.DisplayOrder")"
                            }, {
                                field: "StoreName",
                                width: 100,
                                title: "@T("Plugins.Pickup.PickupInStore.Fields.Store")"
                            }, {
                                field: "Id",
                                title: "@T("Admin.Common.Edit")",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                                template: "<button onclick=\"javascript:OpenWindow('@Url.Content("~/Admin/PickupInStore/Edit/")?id=#=Id#&btnId=btnRefresh&formId=pickup-instore-form', 800, 800, true); return false;\" class='btn btn-default'><i class=\"fa fa-pencil\"></i>@T("Admin.Common.Edit")</button>"
                            }, {
                                command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                                title: "@T("Admin.Common.Delete")",
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                                width: 100
                            }]
                        });
                    });
                </script>
            </div>
            <div class="panel-footer">
                <input type="submit" id="btnAddNewOption" class="btn btn-primary" value="@T("Plugins.Pickup.PickupInStore.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("Create", "PickupInStore",  new { btnId = "btnRefresh", formId = "pickup-instore-form" }))', 800, 800, true); return false;"/>
                <input type="submit" id="btnRefresh" class="btn btn-default" style="display: none" />
            </div>
            <script>
                $(document).ready(function () {
                    $('#btnRefresh').click(function () {
                        //refresh grid
                        var grid = $("#pickup-points-grid").data('kendoGrid');
                        //grid.dataSource.page(1); //new search. Set page size to 1
                        grid.dataSource.read();

                        //return false to don't reload a page
                        return false;
                    });
                });
            </script>
        </div>
    </div>
</form>